package metrics_sql

const (
	MaxMaxApplicationKubernetes = `
object = "%v"
platform = "%v"
metric = "%v"
guid = "%v"
start = %v
end = %v

ct =  from(bucket: "data")
  |> range(start: start, stop: end)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "metrics")
  |> filter(fn: (r) => r["label"] == metric)
  |> filter(fn: (r) => r["platform"] == platform)
  |> filter(fn: (r) => r["object"] == object)
  |> filter(fn: (r) => r["application_guid"] == guid)
  |> max(column: "_value")
  |> group(columns: ["label","platform","object","application_guid"])
  |> max(column: "_value")
  |> map(fn: (r) => ({container:r["container"]}))

data = from(bucket: "data")
  |> range(start: start, stop: end)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "metrics")
  |> filter(fn: (r) => r["label"] == metric)
  |> filter(fn: (r) => r["platform"] == platform)
  |> filter(fn: (r) => r["object"] == object)
  |> filter(fn: (r) => r["application_guid"] == guid)

join(tables: {data: data, ct: ct}, on: [ "container"])
`
	MaxMaxApplicationGluenets = `
object = "%v"
platform = "%v"
metric = "%v"
guid = /^(%v_)/
start = %v
end = %v

ct = from(bucket: "data")
  |> range(start: start, stop: end)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "metrics")
  |> filter(fn: (r) => r["label"] == metric)
  |> filter(fn: (r) => r["platform"] == platform)
  |> filter(fn: (r) => r["object"] == object)
  |> filter(fn: (r) => r["container"] =~ guid)
  |> filter(fn: (r) => r["agent_guidd"] != "")
  |> max(column: "_value")
  |> group(columns: ["label","platform","object","container"])
  |> max(column: "_value")
  |> map(fn: (r) => ({container:r["container"]}))

  data = from(bucket: "data")
   |> range(start: start, stop: end)
   |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
   |> filter(fn: (r) => r["label"] == metric)
   |> filter(fn: (r) => r["platform"] == platform)
   |> filter(fn: (r) => r["object"] == object)
   |> filter(fn: (r) => r["container"] =~ guid)
   |> filter(fn: (r) => r["agent_guid"] != "")

join(tables: {data: data, ct: ct}, on: [ "container"]) 
`

	AvgMaxApplicationKubernetes = `
object = "%v"
platform = "%v"
metric = "%v"
guid = "%v"
start = %v
end = %v

ct =  from(bucket: "data")
	|> range(start: start, stop: end)
	|> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
	|> filter(fn: (r) => r["_field"] == "metrics")
	|> filter(fn: (r) => r["label"] == metric)
	|> filter(fn: (r) => r["platform"] == platform)
	|> filter(fn: (r) => r["object"] == object)
	|> filter(fn: (r) => r["application_guid"] == guid)
	|> mean(column: "_value")
	|> group(columns: ["label","platform","object","application_guid"])
	|> max(column: "_value")
	|> map(fn: (r) => ({container:r["container"]}))

data = from(bucket: "data")
	|> range(start: start, stop: end)
	|> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
	|> filter(fn: (r) => r["_field"] == "metrics")
	|> filter(fn: (r) => r["label"] == metric)
	|> filter(fn: (r) => r["platform"] == platform)
	|> filter(fn: (r) => r["object"] == object)
	|> filter(fn: (r) => r["application_guid"] == guid)

join(tables: {data: data, ct: ct}, on: ["container"])
`

	AvgMaxApplicationGluenets = `
object = "%v"
platform = "%v"
metric = "%v"
guid = /^(%v_)/
start = %v
end = %v

ct = from(bucket: "data")
  |> range(start: start, stop: end)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "metrics")
  |> filter(fn: (r) => r["label"] == metric)
  |> filter(fn: (r) => r["platform"] == platform)
  |> filter(fn: (r) => r["object"] == object)
  |> filter(fn: (r) => r["container"] =~ guid)
  |> filter(fn: (r) => r["agent_guid"] != "")
  |> mean(column: "_value")
  |> group(columns: ["label","platform","object","container"])
  |> max(column: "_value")
  |> map(fn: (r) => ({container:r["container"]}))

  data = from(bucket: "data")
   |> range(start: start, stop: end)
   |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
   |> filter(fn: (r) => r["label"] == metric)
   |> filter(fn: (r) => r["platform"] == platform)
   |> filter(fn: (r) => r["object"] == object)
   |> filter(fn: (r) => r["container"] =~ guid)
   |> filter(fn: (r) => r["agent_guid"] != "")

join(tables: {data: data, ct: ct}, on: [ "container"]) 
`

	AvgMinApplicationKubernetes = `
object = "%v"
platform = "%v"
metric = "%v"
guid = "%v"
start = %v
end = %v

ct =  from(bucket: "data")
	|> range(start: start, stop: end)
	|> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
	|> filter(fn: (r) => r["_field"] == "metrics")
	|> filter(fn: (r) => r["label"] == metric)
	|> filter(fn: (r) => r["platform"] == platform)
	|> filter(fn: (r) => r["object"] == object)
	|> filter(fn: (r) => r["application_guid"] == guid)
	|> mean(column: "_value")
	|> group(columns: ["label","platform","object","application_guid"])
	|> min(column: "_value")
	|> map(fn: (r) => ({container:r["container"]}))

data = from(bucket: "data")
	|> range(start: start, stop: end)
	|> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
	|> filter(fn: (r) => r["_field"] == "metrics")
	|> filter(fn: (r) => r["label"] == metric)
	|> filter(fn: (r) => r["platform"] == platform)
	|> filter(fn: (r) => r["object"] == object)
	|> filter(fn: (r) => r["application_guid"] == guid)

join(tables: {data: data, ct: ct}, on: ["container"])
`

	AvgMinApplicationGluenets = `
object = "%v"
platform = "%v"
metric = "%v"
guid = /^(%v_)/
start = %v
end = %v

ct = from(bucket: "data")
  |> range(start: start, stop: end)
  |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
  |> filter(fn: (r) => r["_field"] == "metrics")
  |> filter(fn: (r) => r["label"] == metric)
  |> filter(fn: (r) => r["platform"] == platform)
  |> filter(fn: (r) => r["object"] == object)
  |> filter(fn: (r) => r["container"] =~ guid)
  |> filter(fn: (r) => r["agent_guid"] != "")
  |> mean(column: "_value")
  |> group(columns: ["label","platform","object","container"])
  |> min(column: "_value")
  |> map(fn: (r) => ({container:r["container"]}))

  data = from(bucket: "data")
   |> range(start: start, stop: end)
   |> filter(fn: (r) => r["_measurement"] == "prometheus_remote_write")
   |> filter(fn: (r) => r["label"] == metric)
   |> filter(fn: (r) => r["platform"] == platform)
   |> filter(fn: (r) => r["object"] == object)
   |> filter(fn: (r) => r["container"] =~ guid)
   |> filter(fn: (r) => r["agent_guid"] != "")

join(tables: {data: data, ct: ct}, on: [ "container"]) 
`
)
